import Wallpaper from '../model/wallpaper.model.ts'
import { selectResultsHandle } from '../utils/common.ts'

class WallpaperService {
  // 查询所有壁纸
  async selectAllWallpaper() {
    const res = await Wallpaper.findAll({
      attributes: ['imgname', 'size'],
    })
    return selectResultsHandle(res)
  }

  // 新增壁纸
  async addWallpaper(imgname: string, size: number) {
    const res = await Wallpaper.create({
      imgname,
      size,
    })
    return res ? res.dataValues : null
  }

  // 清空表
  async deleteWallpaper() {
    const res = await Wallpaper.destroy({ truncate: true })
    return res
  }
}

const wallpaperService = new WallpaperService()
export const { selectAllWallpaper, addWallpaper, deleteWallpaper } =
  wallpaperService
export default wallpaperService
